home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / midasdll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-16  |  45.5 KB  |  1,714 lines

  1. /*      midasdll.c
  2.  *
  3.  * MIDAS DLL programming interface
  4.  *
  5.  * $Id: midasdll.c,v 1.6 1997/01/16 19:57:19 pekangas Exp $
  6.  *
  7.  * Copyright 1996,1997 Housemarque Inc.
  8.  *
  9.  * This file is part of the MIDAS Sound System, and may only be
  10.  * used, modified and distributed under the terms of the MIDAS
  11.  * Sound System license, LICENSE.TXT. By continuing to use,
  12.  * modify or distribute this file you indicate that you have
  13.  * read the license and understand and accept it fully.
  14. */
  15.  
  16. #if defined(__NT__) || defined(__WINDOWS__)
  17. #define WIN32_LEAN_AND_MEAN
  18. #include <windows.h>
  19. #endif
  20.  
  21. #include "midas.h"
  22.  
  23. /* This is a kluge, but necessary as Watcom C sucks: */
  24. #if defined(DLL_EXPORT)
  25. #define EXPORT_IN_MIDASDLL_H
  26. #endif
  27.  
  28. #include "midasdll.h"
  29.  
  30.  
  31. RCSID(const char *midasdll_rcsid = "$Id: midasdll.c,v 1.6 1997/01/16 19:57:19 pekangas Exp $";)
  32.  
  33.  
  34.     /* Channel numbers used with gmpPlaySong(): */
  35. static unsigned midasSDChannels[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
  36.     12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  37.     30, 31 };
  38.  
  39. static int      lastError;
  40. static int      MIDASthread = 0;
  41. #ifdef __WIN32__
  42. static volatile int DLLinUse = 0;
  43. #endif
  44. static int      midasFxInit, midasStrInit;
  45.  
  46.  
  47. _FUNC(int) MIDASgetLastError(void)
  48. {
  49.     return lastError;
  50. }
  51.  
  52.  
  53. _FUNC(char*) MIDASgetErrorMessage(int errorCode)
  54. {
  55.     return errorMsg[errorCode];
  56. }
  57.  
  58.  
  59.  
  60.  
  61. /****************************************************************************\
  62. *
  63. * Function:     BOOL MIDASstartup(void)
  64. *
  65. * Description:  Sets all configuration variables to default values and
  66. *               prepares MIDAS for use. This function must be called before
  67. *               ANY other MIDAS function, including MIDASinit and
  68. *               MIDASsetOption. After this function has been called,
  69. *               MIDASclose can be called at any point, regarless of whether
  70. *               MIDAS has been initialized or not.
  71. *
  72. * Returns:      TRUE if successful, FALSE if not
  73. *
  74. \****************************************************************************/
  75.  
  76. _FUNC(BOOL) MIDASstartup(void)
  77. {
  78.     MIDASthread = 0;
  79.     midasFxInit = 0;
  80.     midasStrInit = 0;
  81.     midasSetDefaults();
  82.  
  83.     return TRUE;
  84. }
  85.  
  86.  
  87.  
  88.  
  89. /****************************************************************************\
  90. *
  91. * Function:     BOOL MIDASdetectSD(void)
  92. *
  93. * Description:  Attempts to detect a Sound Device. Sets the global variable
  94. *               midasSD to point to the detected Sound Device or NULL if no
  95. *               Sound Device was detected
  96. *
  97. * Returns:      TRUE if successful, FALSE if not
  98. *
  99. \****************************************************************************/
  100.  
  101. _FUNC(BOOL) MIDASdetectSD(void)
  102. {
  103.     int         dsd;
  104.     int         error;
  105.     static int  dResult;
  106.  
  107.     midasSD = NULL;                     /* no Sound Device detected yet */
  108.     midasSDNumber = -1;
  109.     dsd = 0;                            /* start from first Sound Device */
  110.  
  111.     /* search through Sound Devices until a Sound Device is detected: */
  112.     while ( (midasSD == NULL) && (dsd < NUMSDEVICES) )
  113.     {
  114.         /* attempt to detect current SD: */
  115.         if ( (error = (*midasSoundDevices[dsd]->Detect)(&dResult)) != OK )
  116.         {
  117.             lastError = error;
  118.             return FALSE;
  119.         }
  120.         if ( dResult == 1 )
  121.         {
  122.             midasSDNumber = dsd;        /* Sound Device detected */
  123.             /* point midasSD to this Sound Device: */
  124.             midasSD = midasSoundDevices[dsd];
  125.         }
  126.         dsd++;                          /* try next Sound Device */
  127.     }
  128.  
  129.     return TRUE;
  130. }
  131.  
  132.  
  133.  
  134.  
  135. /****************************************************************************\
  136. *
  137. * Function:     BOOL midasInit(void);
  138. *
  139. * Description:  Initializes MIDAS Sound System
  140. *
  141. * Returns:      TRUE if successful, FALSE if not
  142. *
  143. \****************************************************************************/
  144.  
  145. _FUNC(BOOL) MIDASinit(void)
  146. {
  147.     int         error;
  148.     static int  dResult;
  149.  
  150.     midasEMSInit = 0;
  151.     mUseEMS = 0;
  152.  
  153.     if ( midasSDNumber == -1 )      /* has a Sound Device been selected? */
  154.     {
  155.         /* attempt to detect Sound Device */
  156.         if ( !MIDASdetectSD() )
  157.         {
  158.             return FALSE;
  159.         }
  160.  
  161.         if ( midasSD == NULL )
  162.         {
  163.             lastError = errSDFailure;
  164.             return FALSE;
  165.         }
  166.     }
  167.     else
  168.     {
  169.         /* use selected Sound Device: */
  170.         midasSD = midasSoundDevices[midasSDNumber];
  171.  
  172.         /* Sound Device number was forced, but if no I/O port, IRQ, DMA or
  173.            sound card type has been set, try to autodetect the values for this
  174.            Sound Device. If detection fails, use default values: */
  175.  
  176.         if ( (midasSDPort == -1) && (midasSDIRQ == -1) &&
  177.             (midasSDDMA == -1) && (midasSDCard == -1) )
  178.             if ( (error = midasSD->Detect(&dResult)) != OK )
  179.             {
  180.                 lastError = error;
  181.                 return FALSE;
  182.             }
  183.     }
  184.  
  185.     if ( midasSDPort != -1 )            /* has an I/O port been selected? */
  186.         midasSD->port = midasSDPort;    /* if yes, set it to Sound Device */
  187.     if ( midasSDIRQ != -1 )             /* SD IRQ number? */
  188.         midasSD->IRQ = midasSDIRQ;      /* if yes, set it to Sound Device */
  189.     if ( midasSDDMA != -1 )             /* SD DMA channel number? */
  190.         midasSD->DMA = midasSDDMA;
  191.     if ( midasSDCard != -1 )            /* sound card type? */
  192.         midasSD->cardType = midasSDCard;
  193.  
  194. #if defined (__DOS__) && (!defined(NOTIMER))
  195.     /* initialize TempoTimer: */
  196.     if ( (error = tmrInit()) != OK )
  197.     {
  198.         lastError = error;
  199.         return FALSE;
  200.     }
  201.  
  202.     midasTMRInit = 1;                 /* TempoTimer initialized */
  203. #endif
  204.  
  205.     /* initialize Sound Device: */
  206.     if ( (error = midasSD->Init(midasMixRate, midasOutputMode)) != OK )
  207.     {
  208.         lastError = error;
  209.         return FALSE;
  210.     }
  211.  
  212.     midasSDInit = 1;                  /* Sound Device initialized */
  213.  
  214.  
  215. #if defined (__DOS__) && (!defined(NOTIMER))
  216.     /* start playing sound using the timer: */
  217.     if ( (error = tmrPlaySD(midasSD)) != OK )
  218.     {
  219.         lastError = error;
  220.         return FALSE;
  221.     }
  222.     midasTMRPlay = 1;
  223. #endif
  224.  
  225.  
  226.     /* Initialize Generic Module Player: */
  227.     if ( (error = gmpInit(midasSD)) != OK )
  228.     {
  229.         lastError = error;
  230.         return FALSE;
  231.     }
  232.     midasGMPInit = 1;
  233.  
  234.     /* Initialize Sound Effects library: */
  235.     if ( (error = fxInit(midasSD)) != OK )
  236.     {
  237.         lastError = error;
  238.         return FALSE;
  239.     }
  240.     midasFxInit = 1;
  241.  
  242. #ifdef SUPPORTSTREAMS
  243.     /* Initialize stream player library: */
  244.     if ( (error = strInit(midasSD)) != OK )
  245.     {
  246.         lastError = error;
  247.         return FALSE;
  248.     }
  249.     midasStrInit = 1;
  250. #endif
  251.  
  252.     return TRUE;
  253. }
  254.  
  255.  
  256.  
  257.  
  258. /****************************************************************************\
  259. *
  260. * Function:     BOOL MIDASclose(void)
  261. *
  262. * Description:  Uninitializes MIDAS Sound System
  263. *
  264. * Returns:      TRUE if successful, FALSE if not
  265. *
  266. \****************************************************************************/
  267.  
  268. _FUNC(BOOL) MIDASclose(void)
  269. {
  270.     int         error;
  271.  
  272. #if defined(__WIN32__) || defined(__LINUX__)
  273.     /* Stop playing thread: */
  274.     if ( MIDASthread )
  275.         MIDASstopBackgroundPlay();
  276. #endif
  277.  
  278. #if defined (__DOS__) && (!defined(NOTIMER))
  279.     /* if music is being played with timer, stop it: */
  280.     if ( midasTMRMusic )
  281.     {
  282.         if ( (error = gmpSetUpdRateFunct(NULL)) != OK )
  283.         {
  284.             lastError = error;
  285.             return FALSE;
  286.         }
  287.         if ( (error = tmrStopMusic(midasPlayerNum)) != OK )
  288.         {
  289.             lastError = error;
  290.             return FALSE;
  291.         }
  292.         midasTMRMusic = 0;
  293.     }
  294. #endif
  295.  
  296.  
  297. #ifdef SUPPORTSTREAMS
  298.     /* Uninitialize stream player if initialized: */
  299.     if ( midasStrInit )
  300.     {
  301.         if ( (error = strClose()) != OK )
  302.         {
  303.             lastError = error;
  304.             return FALSE;
  305.         }
  306.         midasStrInit = 0;
  307.     }
  308. #endif
  309.  
  310.     /* Uninitialize sound effect library if initialized: */
  311.     if ( midasFxInit )
  312.     {
  313.         if ( (error = fxClose()) != OK )
  314.         {
  315.             lastError = error;
  316.             return FALSE;
  317.         }
  318.         midasFxInit = 0;
  319.     }
  320.  
  321.     /* If music is being played, stop it: */
  322.     if ( midasGMPPlay )
  323.     {
  324.         if ( (error = gmpStopSong(midasPlayHandle)) != OK )
  325.         {
  326.             lastError = error;
  327.             return FALSE;
  328.         }
  329.         midasGMPPlay = 0;
  330.     }
  331.  
  332.     /* If Generic Module Player has been initialized, uninitialize it: */
  333.     if ( midasGMPInit )
  334.     {
  335.         if ( (error = gmpClose()) != OK )
  336.         {
  337.             lastError = error;
  338.             return FALSE;
  339.         }
  340.         midasGMPInit = 0;
  341.     }
  342.  
  343.     /* if Sound Device channels are open, close them: */
  344.     if ( midasSDChans )
  345.     {
  346.         if ( (error = midasSD->CloseChannels()) != OK )
  347.         {
  348.             lastError = error;
  349.             return FALSE;
  350.         }
  351.         midasSDChans = 0;
  352.         midasChannels = 0;
  353.     }
  354.  
  355. #if defined (__DOS__) && (!defined(NOTIMER))
  356.     /* if sound is being played, stop it: */
  357.     if ( midasTMRPlay )
  358.     {
  359.         if ( (error = tmrStopSD()) != OK )
  360.         {
  361.             lastError = error;
  362.             return FALSE;
  363.         }
  364.         midasTMRPlay = 0;
  365.     }
  366. #endif
  367.  
  368.     /* if Sound Device is initialized, uninitialize it: */
  369.     if ( midasSDInit )
  370.     {
  371.         if ( (error = midasSD->Close()) != OK )
  372.         {
  373.             lastError = error;
  374.             return FALSE;
  375.         }
  376.         midasSDInit = 0;
  377.         midasSD = NULL;
  378.     }
  379.  
  380. #if defined (__DOS__) && (!defined(NOTIMER))
  381.     /* if TempoTimer is initialized, uninitialize it: */
  382.     if ( midasTMRInit )
  383.     {
  384.         if ( (error = tmrClose()) != OK )
  385.         {
  386.             lastError = error;
  387.             return FALSE;
  388.         }
  389.         midasTMRInit = 0;
  390.     }
  391. #endif
  392.  
  393.  
  394.     return TRUE;
  395. }
  396.  
  397.  
  398. /****************************************************************************\
  399. *
  400. * Function:     BOOL MIDASclose(void)
  401. *
  402. * Description:  Uninitializes MIDAS Sound System
  403. *
  404. * Returns:      TRUE if successful, FALSE if not
  405. *
  406. \****************************************************************************/
  407.  
  408. _FUNC(char*) MIDASgetVersionString(void)
  409. {
  410.     return MVERSTR;
  411. }
  412.  
  413.  
  414.  
  415. /****************************************************************************\
  416. *
  417. * Function:     BOOL MIDASopenChannels(int numChans);
  418. *
  419. * Description:  Opens Sound Device channels for sound and music output.
  420. *
  421. * Input:        int numChans            Number of channels to open
  422. *
  423. * Notes:        Channels opened with this function can be used for sound
  424. *               playing, and modules played with midasPlayModule() will be
  425. *               played through the last of these channels. This function is
  426. *               provided so that the same number of channels can be open
  427. *               the whole time throughout the execution of the program,
  428. *               keeping the volume level constant. Note that you must ensure
  429. *               that you open enough channels for all modules, otherwise
  430. *               midasPlayModule() will fail.
  431. *
  432. * Returns:      TRUE if successful, FALSE if not
  433. *
  434. \****************************************************************************/
  435.  
  436. _FUNC(BOOL) MIDASopenChannels(int numChans)
  437. {
  438.     int         error;
  439.  
  440.     midasChannels = numChans;
  441.  
  442.     /* open Sound Device channels: */
  443.     if ( (error = midasSD->OpenChannels(numChans)) != OK )
  444.     {
  445.         lastError = error;
  446.         return FALSE;
  447.     }
  448.     midasSDChans = 1;
  449.  
  450.     /* set amplification level if forced: */
  451.     if ( midasAmplification != -1 )
  452.     {
  453.         if ( (error = midasSD->SetAmplification(midasAmplification)) != OK )
  454.         {
  455.             lastError = error;
  456.             return FALSE;
  457.         }
  458.     }
  459.  
  460.     return TRUE;
  461. }
  462.  
  463.  
  464.  
  465.  
  466. /****************************************************************************\
  467. *
  468. * Function:     BOOL MIDAScloseChannels(void);
  469. *
  470. * Description:  Closes Sound Device channels opened with midasOpenChannels().
  471. *               Do NOT call this function unless you have opened the sound
  472. *               channels used yourself with midasOpenChannels().
  473. *
  474. * Returns:      TRUE if successful, FALSE if not
  475. *
  476. \****************************************************************************/
  477.  
  478. _FUNC(BOOL) MIDAScloseChannels(void)
  479. {
  480.     int         error;
  481.  
  482.     /* Close Sound Device channels: */
  483.     if ( (error = midasSD->CloseChannels()) != OK )
  484.     {
  485.         lastError = error;
  486.         return FALSE;
  487.     }
  488.     midasSDChans = 0;
  489.     midasChannels = 0;
  490.  
  491.     return TRUE;
  492. }
  493.  
  494.  
  495.  
  496. /****************************************************************************\
  497. *
  498. * Function:     MIDASmodule MIDASloadModule(char *fileName)
  499. *
  500. * Description:  Loads a module into memory
  501. *
  502. * Input:        char *fileName          module file name
  503. *
  504. * Returns:      Module handle if successful, NULL if failed
  505. *
  506. \****************************************************************************/
  507.  
  508. _FUNC(MIDASmodule) MIDASloadModule(char *fileName)
  509. {
  510.     static fileHandle  f;
  511.     static char buf[64];
  512.     int         error;
  513.     static gmpModule *module;
  514.  
  515.     /* Check the module type and use the correct module loader
  516.        (fixme, hardwired types and poor detection) */
  517.     if ( (error = fileOpen(fileName, fileOpenRead, &f)) != OK )
  518.     {
  519.         lastError = error;
  520.         return FALSE;
  521.     }
  522.     if ( (error = fileRead(f, buf, 48)) != OK )
  523.     {
  524.         fileClose(f);
  525.         lastError = error;
  526.         return FALSE;
  527.     }
  528.     if ( (error = fileClose(f)) != OK )
  529.     {
  530.         lastError = error;
  531.         return FALSE;
  532.     }
  533.  
  534.     if ( mMemEqual(buf, "Extended Module:", 16) )
  535.     {
  536.         /* It's a FastTracker module: */
  537.         error = gmpLoadXM(fileName, 1, NULL, &module);
  538.     }
  539.     else
  540.     {
  541.         if ( mMemEqual(buf+44, "SCRM", 4) )
  542.         {
  543.             /* It's a Scream Tracker 3 module */
  544.             error = gmpLoadS3M(fileName, 1, NULL, &module);
  545.         }
  546.         else
  547.         {
  548.             /* None of the above - we'll assume it's a Protracker module,
  549.                the loader will fail if this is not the case */
  550.             error = gmpLoadMOD(fileName, 1, NULL, &module);
  551.         }
  552.     }
  553.  
  554.     if ( error != OK )
  555.     {
  556.         lastError = error;
  557.         return NULL;
  558.     }
  559.  
  560.     return (MIDASmodule) module;
  561. }
  562.  
  563.  
  564.  
  565.  
  566. /****************************************************************************\
  567. *
  568. * Function:     BOOL MIDASplayModule(MIDASmodule module,
  569. *                   int numEffectChannels)
  570. *
  571. * Description:  Starts playing a Generic Module Player module loaded to memory
  572. *
  573. * Input:        gmpModule *module       Pointer to loaded module structure
  574. *               int numEffectChns       Number of channels to open for sound
  575. *                                       effects. Ignored if sound channels
  576. *                                       have already been opened with
  577. *                                       midasOpenChannels().
  578. *
  579. * Returns:      TRUE if successful, FALSE if not
  580. *
  581. * Notes:        The Sound Device channels available for sound effects are the
  582. *               _first_ numEffectChns channels. So, for example, if you use
  583. *               midasPlayModule(module, 3), you can use channels 0-2 for sound
  584. *               effects. If you already have opened channels with
  585. *               midasOpenChannels(), the module will be played with the last
  586. *               possible channels, so that the first channels will be
  587. *               available for sound effects. Note that if not enough channels
  588. *               are open this function will fail.
  589. *
  590. \****************************************************************************/
  591.  
  592. _FUNC(BOOL) MIDASplayModule(MIDASmodule module, int numEffectChannels)
  593. {
  594.     short       numChans;
  595.     int         error;
  596.     int         firstChannel;
  597.     gmpModule   *gmpmod = (gmpModule*) module;
  598.  
  599.     numChans = gmpmod->numChannels;
  600.  
  601.     /* Open Sound Device channels if not already open: */
  602.     if ( midasChannels == 0 )
  603.     {
  604.         if ( (error = midasSD->OpenChannels(numChans + numEffectChannels))
  605.             != OK )
  606.         {
  607.             lastError = error;
  608.             return FALSE;
  609.         }
  610.         midasSDChans = 1;
  611.         firstChannel = numEffectChannels;
  612.  
  613.         /* set amplification level if forced: */
  614.         if ( midasAmplification != -1 )
  615.         {
  616.             if ( (error = midasSD->SetAmplification(midasAmplification))
  617.                 != OK )
  618.             {
  619.                 lastError = error;
  620.                 return FALSE;
  621.             }
  622.         }
  623.     }
  624.     else
  625.     {
  626.         if ( midasChannels < numChans )
  627.         {
  628.             lastError = errNoChannels;
  629.             return FALSE;
  630.         }
  631.         firstChannel = midasChannels - numChans;
  632.     }
  633.  
  634.     /* Start playing the whole song in the module using the last Sound Device
  635.        channels: */
  636.     if ( (error = gmpPlaySong(gmpmod    , -1, -1, -1, -1,
  637.         &midasSDChannels[firstChannel], &midasPlayHandle)) != OK )
  638.     {
  639.         lastError = error;
  640.         return FALSE;
  641.     }
  642.     midasGMPPlay = 1;
  643.  
  644. #if defined (__DOS__) && (!defined(NOTIMER))
  645.     /* Start playing using the timer: */
  646.     if ( (error = tmrPlayMusic(&gmpPlay, &midasPlayerNum)) != OK )
  647.     {
  648.         lastError = error;
  649.         return FALSE;
  650.     }
  651.     if ( (error = gmpSetUpdRateFunct(&tmrSetUpdRate)) != OK )
  652.     {
  653.         lastError = error;
  654.         return FALSE;
  655.     }
  656.  
  657.     midasTMRMusic = 1;
  658. #endif
  659.  
  660.  
  661.     return TRUE;
  662. }
  663.  
  664.  
  665.  
  666.  
  667. /****************************************************************************\
  668. *
  669. * Function:     BOOL MIDASstopModule(gmpModule *module)
  670. *
  671. * Input:        gmpModule *module       the module which is being played
  672. *
  673. * Description:  Stops playing a module and uninitializes the Module Player.
  674. *               If sound channels were NOT opened through midasOpenChannels(),
  675. *               but by letting midasPlayModule() open them, they will be
  676. *               closed. Sound channels opened with midasOpenChannels() are NOT
  677. *               closed and must be closed separately.
  678. *
  679. * Returns:      TRUE if successful, FALSE if not
  680. *
  681. \****************************************************************************/
  682.  
  683. _FUNC(BOOL) MIDASstopModule(MIDASmodule module)
  684. {
  685.     int         error, i;
  686.     gmpModule   *gmpmod = (gmpModule*) module;
  687.  
  688. #if defined (__DOS__) && (!defined(NOTIMER))
  689.     /* Stop playing music with timer: */
  690.     if ( (error = gmpSetUpdRateFunct(NULL)) != OK )
  691.     {
  692.         lastError = error;
  693.         return FALSE;
  694.     }
  695.     if ( (error = tmrStopMusic(midasPlayerNum)) != OK )
  696.     {
  697.         lastError = error;
  698.         return FALSE;
  699.     }
  700.  
  701.     midasTMRMusic = 0;
  702. #endif
  703.  
  704.     /* Stop playing the module: */
  705.     if ( (error = gmpStopSong(midasPlayHandle)) != OK )
  706.     {
  707.         lastError = error;
  708.         return FALSE;
  709.     }
  710.     midasGMPPlay = 0;
  711.     midasPlayHandle = NULL;
  712.  
  713.     /* If Sound Device channels were not opened with midasOpenChannels(),
  714.        close them: */
  715.     if ( midasChannels == 0 )
  716.     {
  717.         if ( (error = midasSD->CloseChannels()) != OK )
  718.         {
  719.             lastError = error;
  720.             return FALSE;
  721.         }
  722.         midasSDChans = 0;
  723.     }
  724.     else
  725.     {
  726.         /* Sound Device channels were originally opened with
  727.            midasOpenChannels(). Now stop sounds from the channels used by
  728.            the Module Player: */
  729.         for ( i = (midasChannels - gmpmod->numChannels); i < midasChannels;
  730.             i++ )
  731.         {
  732.             if ( (error = midasSD->StopSound(i)) != OK )
  733.             {
  734.                 lastError = error;
  735.                 return FALSE;
  736.             }
  737.             if ( (error = midasSD->SetVolume(i, 0)) != OK )
  738.             {
  739.                 lastError = error;
  740.                 return FALSE;
  741.             }
  742.         }
  743.     }
  744.  
  745.     return TRUE;
  746. }
  747.  
  748.  
  749.  
  750. /****************************************************************************\
  751. *
  752. * Function:     BOOL MIDASfreeModule(MIDASmodule module)
  753. *
  754. * Description:  Deallocates a module loaded with MIDASloadModule();
  755. *
  756. * Input:        DWORD module            module handle
  757. *
  758. * Returns:      TRUE if successful, FALSE if not
  759. *
  760. \****************************************************************************/
  761.  
  762. _FUNC(BOOL) MIDASfreeModule(MIDASmodule module)
  763. {
  764.     int         error;
  765.  
  766.     if ( (error = gmpFreeModule((gmpModule*) module)) != OK )
  767.     {
  768.         lastError = error;
  769.         return FALSE;
  770.     }
  771.  
  772.     return TRUE;
  773. }
  774.  
  775.  
  776.  
  777. /****************************************************************************\
  778. *
  779. * Function:     BOOL MIDASstartBackgroundPlay(DWORD pollRate)
  780. *
  781. * Description:  Starts playing music in the background
  782. *
  783. * Input:        DWORD pollRate          polling rate (in Hz - polls per
  784. *                                       second)
  785. *
  786. * Returns:      TRUE if successful, FALSE if not
  787. *
  788. \****************************************************************************/
  789.  
  790. _FUNC(BOOL) MIDASstartBackgroundPlay(DWORD pollRate)
  791. {
  792. #if defined(__WIN32__) || defined(__LINUX__)
  793.     DWORD       pollPeriod;
  794.  
  795.     /* Calculate delay between polls - default is 20ms, otherwise calculate
  796.        delay based on rate, and divide by two to make sure polling is done
  797.        at least often enough */
  798.     if ( !pollRate )
  799.         pollPeriod = 20;
  800.     else
  801.         pollPeriod = 1000 / pollRate / 2;
  802.  
  803.     StartPlayThread(pollPeriod);
  804.     MIDASthread = 1;
  805. #else
  806.     pollRate = pollRate;
  807. #endif
  808.     return TRUE;
  809. }
  810.  
  811.  
  812.  
  813.  
  814. /****************************************************************************\
  815. *
  816. * Function:     BOOL MIDASstopBackgroundPlay(void)
  817. *
  818. * Description:  Stops playing music in the background
  819. *
  820. * Returns:      TRUE if successful, FALSE if not
  821. *
  822. \****************************************************************************/
  823.  
  824. _FUNC(BOOL) MIDASstopBackgroundPlay(void)
  825. {
  826. #if defined(__WIN32__) || defined(__LINUX__)
  827.     if ( !MIDASthread )
  828.         return TRUE;
  829.  
  830.     StopPlayThread();
  831.     MIDASthread = 0;
  832. #endif
  833.     return TRUE;
  834. }
  835.  
  836.  
  837. #if defined(__WIN32__) || defined(__LINUX__)
  838.  
  839.  
  840. /****************************************************************************\
  841. *
  842. * Function:     BOOL MIDASpoll(void)
  843. *
  844. * Description:  Polls the sound and music player manually
  845. *
  846. * Returns:      TRUE if successful, FALSE if not
  847. *
  848. \****************************************************************************/
  849.  
  850. _FUNC(BOOL) MIDASpoll(void)
  851. {
  852.     PollMIDAS();
  853.  
  854.     return TRUE;
  855. }
  856.  
  857.  
  858. #endif /* #if defined(__WIN32__) || defined(__LINUX__) */
  859.  
  860.  
  861.  
  862.  
  863.  
  864. /****************************************************************************\
  865. *
  866. * Function:     BOOL MIDASsetOption(int option, int value);
  867. *
  868. * Description:  Sets a MIDAS option
  869. *
  870. * Input:        int option              option (see enum MIDASoptions)
  871. *               int value               value for the option
  872. *
  873. * Returns:      TRUE if successful, FALSE if not
  874. *
  875. \****************************************************************************/
  876.  
  877. _FUNC(BOOL) MIDASsetOption(int option, int value)
  878. {
  879.     switch ( option )
  880.     {
  881.         case MIDAS_OPTION_MIXRATE:
  882.             midasMixRate = value;
  883.             return TRUE;
  884.  
  885.         case MIDAS_OPTION_OUTPUTMODE:
  886.             midasOutputMode = value;
  887.             return TRUE;
  888.  
  889.         case MIDAS_OPTION_MIXBUFLEN:
  890.             mBufferLength = value;
  891.             return TRUE;
  892.  
  893.         case MIDAS_OPTION_MIXBUFBLOCKS:
  894.             mBufferBlocks = value;
  895.             return TRUE;
  896.     }
  897.  
  898.     return TRUE;
  899. }
  900.  
  901.  
  902.  
  903. /****************************************************************************\
  904. *
  905. * Function:     MIDASsample MIDASloadRawSample(char *filename, int sampleType,
  906. *                   int loopSample)
  907. *
  908. * Description:  Loads a raw sound effect sample
  909. *
  910. * Input:        char *filename          sample file name
  911. *               int sampleType          sample type
  912. *               int loopSample          1 if sample should be looped
  913. *
  914. * Returns:      MIDAS sample handle, NULL if failed
  915. *
  916. \****************************************************************************/
  917.  
  918. _FUNC(MIDASsample) MIDASloadRawSample(char *fileName, int sampleType,
  919.     int loopSample)
  920. {
  921.     int         error;
  922.     static unsigned sampleHandle;
  923.  
  924.     /* Load the sample: */
  925.     if ( (error = fxLoadRawSample(fileName, sampleType, loopSample,
  926.         &sampleHandle)) != OK )
  927.     {
  928.         lastError = error;
  929.         return 0;
  930.     }
  931.  
  932.     return sampleHandle;
  933. }
  934.  
  935.  
  936.  
  937.  
  938. /****************************************************************************\
  939. *
  940. * Function:     BOOL MIDASfreeSample(MIDASsample sample)
  941. *
  942. * Description:  Deallocates a sample
  943. *
  944. * Input:        MIDASsample sample      sample to be deallocated
  945. *
  946. * Returns:      TRUE if succesful, FALSE if not
  947. *
  948. \****************************************************************************/
  949.  
  950. _FUNC(BOOL) MIDASfreeSample(MIDASsample sample)
  951. {
  952.     int         error;
  953.  
  954.     if ( (error = fxFreeSample(sample)) != OK )
  955.     {
  956.         lastError = error;
  957.         return FALSE;
  958.     }
  959.  
  960.     return TRUE;
  961. }
  962.  
  963.  
  964.  
  965. /****************************************************************************\
  966. *
  967. * Function:     BOOL MIDASsetAutoEffectChannels(unsigned firstChannel,
  968. *                   unsigned numChannels)
  969. *
  970. * Description:  Sets the range of channels that can be used for automatic
  971. *               sound effect channels
  972. *
  973. * Input:        unsigned firstChannel   first channel to use
  974. *               unsigned numChannels    number of channels to use
  975. *
  976. * Returns:      TRUE if successful, FALSE if not
  977. *
  978. \****************************************************************************/
  979.  
  980. _FUNC(BOOL) MIDASsetAutoEffectChannels(unsigned firstChannel,
  981.     unsigned numChannels)
  982. {
  983.     unsigned    *numbers;
  984.     int         error;
  985.     unsigned    i;
  986.     unsigned    n;
  987.  
  988.     /* Allocate memory for channel number table: */
  989.     if ( (error = memAlloc(numChannels * sizeof(unsigned), (void**) &numbers))
  990.         != OK )
  991.     {
  992.         lastError = error;
  993.         return FALSE;
  994.     }
  995.  
  996.     /* Fill the table with the channel numbers: */
  997.     n = firstChannel;
  998.     for ( i = 0; i < numChannels; i++ )
  999.         numbers[i] = n++;
  1000.  
  1001.     /* Set the channels: */
  1002.     if ( (error = fxSetAutoChannels(numChannels, numbers)) != OK )
  1003.     {
  1004.         memFree(numbers);
  1005.         lastError = error;
  1006.         return FALSE;
  1007.     }
  1008.  
  1009.     /* Free the number table: */
  1010.     if ( (error = memFree(numbers)) != OK )
  1011.     {
  1012.         lastError = error;
  1013.         return FALSE;
  1014.     }
  1015.  
  1016.     return TRUE;
  1017. }
  1018.  
  1019.  
  1020.  
  1021.  
  1022. /****************************************************************************\
  1023. *
  1024. * Function:     MIDASsamplePlayHandle MIDASplaySample(MIDASsample sample,
  1025. *                   unsigned channel, int priority, unsigned rate,
  1026. *                   unsigned volume, int panning)
  1027. *
  1028. * Description:  Plays a sound effect sample
  1029. *
  1030. * Input:        MIDASsample sample      sample to be played
  1031. *               unsigned channel        channel the sample should be played
  1032. *                                       on, MIDAS_CHANNEL_AUTO for automatic
  1033. *                                       selection
  1034. *               int priority            sample playing priority, the higher
  1035. *                                       the value the higher the priority
  1036. *               unsigned rate           initial sample rate
  1037. *               unsigned volume         initial volume
  1038. *               int panning             initial panning position
  1039. *
  1040. * Returns:      Sample playing handle or NULL if failed
  1041. *
  1042. \****************************************************************************/
  1043.  
  1044. _FUNC(MIDASsamplePlayHandle) MIDASplaySample(MIDASsample sample,
  1045.     unsigned channel, int priority, unsigned rate, unsigned volume,
  1046.     int panning)
  1047. {
  1048.     int         error;
  1049.     static unsigned playHandle;
  1050.  
  1051.     if ( (error = fxPlaySample(channel, sample, priority, rate, volume,
  1052.         panning, &playHandle)) != OK )
  1053.     {
  1054.         lastError = error;
  1055.         return 0;
  1056.     }
  1057.  
  1058.     /* KLUGE! Add 1 to the handle to make sure NULL is an illegal handle: */
  1059.     return playHandle + 1;
  1060. }
  1061.  
  1062.  
  1063.  
  1064.  
  1065. /****************************************************************************\
  1066. *
  1067. * Function:     BOOL MIDASstopSample(MIDASsamplePlayHandle sample)
  1068. *
  1069. * Description:  Stops playing a sample
  1070. *
  1071. * Input:        MIDASsamplePlayHandle sample    sample playing handle
  1072. *
  1073. * Returns:      TRUE if successful, FALSE if not
  1074. *
  1075. \****************************************************************************/
  1076.  
  1077. _FUNC(BOOL) MIDASstopSample(MIDASsamplePlayHandle sample)
  1078. {
  1079.     int         error;
  1080.  
  1081.     if ( (error = fxStopSample(sample-1)) != OK )
  1082.     {
  1083.         lastError = error;
  1084.         return FALSE;
  1085.     }
  1086.  
  1087.     return TRUE;
  1088. }
  1089.  
  1090.  
  1091.  
  1092. /****************************************************************************\
  1093. *
  1094. * Function:     BOOL MIDASsetSampleRate(MIDASsamplePlayHandle sample,
  1095. *                   unsigned rate)
  1096. *
  1097. * Description:  Changes the sample rate for a sound effect sample that is
  1098. *               being played
  1099. *
  1100. * Input:        MIDASsamplePlayHandle sample    sample to change
  1101. *               unsigned rate                   new rate
  1102. *
  1103. * Returns:      TRUE if succesful, FALSE if not
  1104. *
  1105. \****************************************************************************/
  1106.  
  1107. _FUNC(BOOL) MIDASsetSampleRate(MIDASsamplePlayHandle sample, unsigned rate)
  1108. {
  1109.     int         error;
  1110.  
  1111.     if ( (error = fxSetSampleRate(sample-1, rate)) != OK )
  1112.     {
  1113.         lastError = error;
  1114.         return FALSE;
  1115.     }
  1116.  
  1117.     return TRUE;
  1118. }
  1119.  
  1120.  
  1121.  
  1122. /****************************************************************************\
  1123. *
  1124. * Function:     BOOL MIDASsetSampleVolume(MIDASsamplePlayHandle sample,
  1125. *                   unsigned volume)
  1126. *
  1127. * Description:  Changes the volume for a sound effect sample that is being
  1128. *               played
  1129. *
  1130. * Input:        MIDASsamplePlayHandle sample    sample to change
  1131. *               unsigned volume                 new volume
  1132. *
  1133. * Returns:      TRUE if succesful, FALSE if not
  1134. *
  1135. \****************************************************************************/
  1136.  
  1137. _FUNC(BOOL) MIDASsetSampleVolume(MIDASsamplePlayHandle sample,
  1138.     unsigned volume)
  1139. {
  1140.     int         error;
  1141.  
  1142.     if ( (error = fxSetSampleVolume(sample-1, volume)) != OK )
  1143.     {
  1144.         lastError = error;
  1145.         return FALSE;
  1146.     }
  1147.  
  1148.     return TRUE;
  1149. }
  1150.  
  1151.  
  1152.  
  1153. /****************************************************************************\
  1154. *
  1155. * Function:     BOOL MIDASsetSamplePanning(MIDASsamplePlayHandle sample,
  1156. *                   int panning)
  1157. *
  1158. * Description:  Changes the panning position of a sound effect sample that is
  1159. *               being played
  1160. *
  1161. * Input:        MIDASsamplePlayHandle sample    sample to change
  1162. *               int panning                     new panning position
  1163. *
  1164. * Returns:      TRUE if succesful, FALSE if not
  1165. *
  1166. \****************************************************************************/
  1167.  
  1168. _FUNC(BOOL) MIDASsetSamplePanning(MIDASsamplePlayHandle sample,
  1169.     int panning)
  1170. {
  1171.     int         error;
  1172.  
  1173.     if ( (error = fxSetSamplePanning(sample-1, panning)) != OK )
  1174.     {
  1175.         lastError = error;
  1176.         return FALSE;
  1177.     }
  1178.  
  1179.     return TRUE;
  1180. }
  1181.  
  1182.  
  1183.  
  1184. /****************************************************************************\
  1185. *
  1186. * Function:     BOOL MIDASsetSamplePriority(MIDASsamplePlayHandle sample,
  1187. *                   int priority)
  1188. *
  1189. * Description:  Changes the playing priority of a sound effect sample that is
  1190. *               being played
  1191. *
  1192. * Input:        MIDASsamplePlayHandle sample    sample to change
  1193. *               int priority                    new playing priority
  1194. *
  1195. * Returns:      TRUE if succesful, FALSE if not
  1196. *
  1197. \****************************************************************************/
  1198.  
  1199. _FUNC(BOOL) MIDASsetSamplePriority(MIDASsamplePlayHandle sample,
  1200.     int priority)
  1201. {
  1202.     int         error;
  1203.  
  1204.     if ( (error = fxSetSamplePriority(sample-1, priority)) != OK )
  1205.     {
  1206.         lastError = error;
  1207.         return FALSE;
  1208.     }
  1209.  
  1210.     return TRUE;
  1211. }
  1212.  
  1213.  
  1214.  
  1215.  
  1216. /****************************************************************************\
  1217. *
  1218. * Function:     BOOL MIDASgetPlayStatus(MIDASplayStatus *status)
  1219. *
  1220. * Description:  Gets current module playing status
  1221. *
  1222. * Input:        MIDASplayStatus *status     pointer to status structure
  1223. *
  1224. * Returns:      TRUE if successful, FALSE if not.
  1225. *               Module playing status will be written to *status
  1226. *
  1227. \****************************************************************************/
  1228.  
  1229. _FUNC(BOOL) MIDASgetPlayStatus(MIDASplayStatus *status)
  1230. {
  1231.     static gmpInformation *gmpInfo;
  1232.     int         error;
  1233.  
  1234.     /* Check that we really are playing something: */
  1235.     if ( midasPlayHandle == NULL )
  1236.     {
  1237.         status->position = status->pattern = status->row = 0;
  1238.         return TRUE;
  1239.     }
  1240.  
  1241.     /* Get information from GMPlayer: */
  1242.     if ( (error = gmpGetInformation(midasPlayHandle, &gmpInfo)) != OK )
  1243.     {
  1244.         lastError = error;
  1245.         return FALSE;
  1246.     }
  1247.  
  1248.     /* Copy them: */
  1249.     status->position = gmpInfo->position;
  1250.     status->pattern = gmpInfo->pattern;
  1251.     status->row = gmpInfo->row;
  1252.     status->syncInfo = gmpInfo->syncInfo;
  1253.  
  1254.     return TRUE;
  1255. }
  1256.  
  1257.  
  1258.  
  1259.  
  1260. /****************************************************************************\
  1261. *
  1262. * Function:     BOOL MIDASsetPosition
  1263. *
  1264. * Description:  Sets module playback position
  1265. *
  1266. * Input:        int newPosition         new position
  1267. *
  1268. * Returns:      TRUE if successful, FALSE if not
  1269. *
  1270. \****************************************************************************/
  1271.  
  1272. _FUNC(BOOL) MIDASsetPosition(int newPosition)
  1273. {
  1274.     int         error;
  1275.  
  1276.     if ( midasPlayHandle == NULL )
  1277.         return TRUE;
  1278.  
  1279.     if ( (error = gmpSetPosition(midasPlayHandle, newPosition)) != OK )
  1280.     {
  1281.         lastError = error;
  1282.         return FALSE;
  1283.     }
  1284.  
  1285.     return TRUE;
  1286. }
  1287.  
  1288.  
  1289.  
  1290. /****************************************************************************\
  1291. *
  1292. * Function:     BOOL MIDASsetMusicVolume
  1293. *
  1294. * Description:  Sets module playback volume
  1295. *
  1296. * Input:        unsigned volume     new volume
  1297. *
  1298. * Returns:      TRUE if successful, FALSE if not
  1299. *
  1300. \****************************************************************************/
  1301.  
  1302. _FUNC(BOOL) MIDASsetMusicVolume(unsigned volume)
  1303. {
  1304.     if ( midasPlayHandle == NULL )
  1305.         return TRUE;
  1306.  
  1307.     midasPlayHandle->masterVolume = volume;
  1308.  
  1309.     return TRUE;
  1310. }
  1311.  
  1312.  
  1313.  
  1314. /****************************************************************************\
  1315. *
  1316. * Function:     BOOL MIDASgetModuleInfo(MIDASmodule module,
  1317. *                   MIDASmoduleInfo *info)
  1318. *
  1319. * Description:  Gets information about a module
  1320. *
  1321. * Input:        MIDASmodule module      MIDAS module handle
  1322. *               MIDASmoduleInfo *info   pointer to module info structure
  1323. *
  1324. * Returns:      TRUE if successful, FALSE if not. Module information is
  1325. *               written to *info.
  1326. *
  1327. \****************************************************************************/
  1328.  
  1329. _FUNC(BOOL) MIDASgetModuleInfo(MIDASmodule module, MIDASmoduleInfo *info)
  1330. {
  1331.     gmpModule   *gmpMod = (gmpModule*) module;
  1332.  
  1333.     if ( module == NULL )
  1334.     {
  1335.         lastError = errInvalidArguments;
  1336.         return FALSE;
  1337.     }
  1338.  
  1339.     mMemCopy(info->songName, gmpMod->name, 32);
  1340.     info->songName[31] = 0;
  1341.     info->songLength = gmpMod->songLength;
  1342.     info->numInstruments = gmpMod->numInsts;
  1343.     info->numPatterns = gmpMod->numPatts;
  1344.     info->songLength = gmpMod->songLength;
  1345.     info->numChannels = gmpMod->numChannels;
  1346.  
  1347.     return TRUE;
  1348. }
  1349.  
  1350.  
  1351.  
  1352.  
  1353. /****************************************************************************\
  1354. *
  1355. * Function:     BOOL MIDASgetInstrumentInfo(MIDASmodule module, int instNum,
  1356. *                   MIDASinstrumentInfo *info);
  1357. *
  1358. * Description:  Gets information about an instrument in a module
  1359. *
  1360. * Input:        MIDASmodule module      MIDAS module handle
  1361. *               int instNum             instrument number
  1362. *               MIDASinstrumentInfo *info   pointer to destination info struct
  1363. *
  1364. * Returns:      TRUE if successful, FALSE if not. Instrument information is
  1365. *               written to *info.
  1366. *
  1367. \****************************************************************************/
  1368.  
  1369. _FUNC(BOOL) MIDASgetInstrumentInfo(MIDASmodule module, int instNum,
  1370.     MIDASinstrumentInfo *info)
  1371. {
  1372.     gmpModule   *gmpMod = (gmpModule*) module;
  1373.  
  1374.     if ( (module == NULL) || (((unsigned) instNum) >= gmpMod->numInsts) )
  1375.     {
  1376.         lastError = errInvalidArguments;
  1377.         return FALSE;
  1378.     }
  1379.  
  1380.     mMemCopy(info->instName, gmpMod->instruments[instNum]->name, 32);
  1381.     info->instName[31] = 0;
  1382.  
  1383.     return TRUE;
  1384. }
  1385.  
  1386.  
  1387. #ifdef SUPPORTSTREAMS
  1388.  
  1389.  
  1390.  
  1391. /****************************************************************************\
  1392. *
  1393. * Function:     MIDASstreamHandle MIDASplayStreamFile(unsigned channel,
  1394. *                   char *fileName, unsigned sampleType, unsigned sampleRate,
  1395. *                   unsigned bufferLength, int loopStream)
  1396. *
  1397. * Description:  Starts playing a digital audio stream from a file
  1398. *
  1399. * Input:        unsigned channel        channel to play the stream on
  1400. *               char *fileName          stream file name
  1401. *               unsigned sampleType     stream sample type
  1402. *               unsigned sampleRate     stream sampling rate
  1403. *               unsigned bufferLength   stream buffer length in milliseconds
  1404. *               int loopStream          1 if stream should be looped
  1405. *
  1406. * Returns:      Stream handle or NULL if failed
  1407. *
  1408. \****************************************************************************/
  1409.  
  1410. _FUNC(MIDASstreamHandle) MIDASplayStreamFile(unsigned channel,
  1411.     char *fileName, unsigned sampleType, unsigned sampleRate,
  1412.     unsigned bufferLength, int loopStream)
  1413. {
  1414.     int         error;
  1415.     strStream   *stream;
  1416.  
  1417.     if ( (error = strPlayStreamFile(channel, fileName, sampleType, sampleRate,
  1418.         bufferLength, loopStream, &stream)) != OK )
  1419.     {
  1420.         lastError = error;
  1421.         return NULL;
  1422.     }
  1423.  
  1424.     return (MIDASstreamHandle) stream;
  1425. }
  1426.  
  1427.  
  1428.  
  1429.  
  1430. /****************************************************************************\
  1431. *
  1432. * Function:     BOOL MIDASstopStream(MIDASstreamHandle stream)
  1433. *
  1434. * Description:  Stops playing a stream
  1435. *
  1436. * Input:        MIDASstreamHandle stream    stream to be stopped
  1437. *
  1438. * Returns:      TRUE if succesful, FALSE if not
  1439. *
  1440. \****************************************************************************/
  1441.  
  1442. _FUNC(BOOL) MIDASstopStream(MIDASstreamHandle stream)
  1443. {
  1444.     int         error;
  1445.  
  1446.     if ( (error = strStopStream((strStream*) stream)) != OK )
  1447.     {
  1448.         lastError = error;
  1449.         return FALSE;
  1450.     }
  1451.  
  1452.     return TRUE;
  1453. }
  1454.  
  1455.  
  1456. /****************************************************************************\
  1457. *
  1458. * Function:     MIDASstreamHandle MIDASplayStreamPolling(unsigned channel,
  1459.                     unsigned sampleType, unsigned sampleRate,
  1460.                     unsigned bufferLength);
  1461. *
  1462. * Description:  Starts playing a stream in polling mode. Use
  1463. *               MIDASfeedStreamData() to feed the stream data to the player
  1464. *
  1465. * Input:        unsigned channel        channel number for the stream
  1466. *               unsigned sampleType     stream sample type
  1467. *               unsigned sampleRate     stream sampling rate
  1468. *               unsigned bufferLength   stream buffer length in milliseconds
  1469. *
  1470. * Returns:      Stream handle or NULL if failed
  1471. *
  1472. \****************************************************************************/
  1473.  
  1474. _FUNC(MIDASstreamHandle) MIDASplayStreamPolling(unsigned channel,
  1475.     unsigned sampleType, unsigned sampleRate, unsigned bufferLength)
  1476. {
  1477.     int         error;
  1478.     strStream   *stream;
  1479.  
  1480.     if ( (error = strPlayStreamPolling(channel, sampleType, sampleRate,
  1481.         bufferLength, &stream)) != OK )
  1482.     {
  1483.         lastError = error;
  1484.         return NULL;
  1485.     }
  1486.  
  1487.     return (MIDASstreamHandle) stream;
  1488. }
  1489.  
  1490.  
  1491.  
  1492. /****************************************************************************\
  1493. *
  1494. * Function:     unsigned MIDASfeedStreamData(MIDASstreamHandle stream,
  1495.                     unsigned char *data, unsigned numBytes, BOOL feedAll)
  1496. * Description:  Feeds sample data to a stream that is being played in polling
  1497. *               mode.
  1498. *
  1499. * Input:        MIDASstreamHandle stream    Stream playing handle
  1500. *               uchar *data             pointer to stream data
  1501. *               unsigned numBytes       number of bytes of data to feed. Note!
  1502. *                                       This must be a multiple of the stream
  1503. *                                       sample size
  1504. *               BOOL feedAll            TRUE if all data should be fed in all
  1505. *                                       circumstances. The function will block
  1506. *                                       the current thread if this flag is 1
  1507. *                                       until all data is fed.
  1508. *
  1509. * Returns:      The number of bytes of sample data that was actually fed.
  1510. *
  1511. \****************************************************************************/
  1512.  
  1513. _FUNC(unsigned) MIDASfeedStreamData(MIDASstreamHandle stream,
  1514.     unsigned char *data, unsigned numBytes, BOOL feedAll)
  1515. {
  1516.     int         error;
  1517.     unsigned    numFed;
  1518.     int         iFeedAll;
  1519.  
  1520.     if ( feedAll )
  1521.         iFeedAll = 1;
  1522.     else
  1523.         iFeedAll = 0;
  1524.  
  1525.     if ( (error = strFeedStreamData((strStream*) stream, data, numBytes,
  1526.         iFeedAll, &numFed)) != OK )
  1527.     {
  1528.         lastError = error;
  1529.         return 0;
  1530.     }
  1531.  
  1532.     return numFed;
  1533. }
  1534.  
  1535.  
  1536. /****************************************************************************\
  1537. *
  1538. * Function:     BOOL MIDASsetStreamRate(MIDASstreamHandle stream,
  1539. *                   unsigned rate)
  1540. *
  1541. * Description:  Changes the playback rate of a stream
  1542. *
  1543. * Input:        MIDASstreamHandle stream    Stream playing handle
  1544. *               unsigned rate           New playback sample rate, in Hz
  1545. *
  1546. * Returns:      TRUE if succesful, FALSE if not
  1547. *
  1548. \****************************************************************************/
  1549.  
  1550. _FUNC(BOOL) MIDASsetStreamRate(MIDASstreamHandle stream, unsigned rate)
  1551. {
  1552.     int         error;
  1553.  
  1554.     if ( (error = strSetStreamRate((strStream*) stream, rate)) != OK )
  1555.     {
  1556.         lastError = error;
  1557.         return FALSE;
  1558.     }
  1559.  
  1560.     return TRUE;
  1561. }
  1562.  
  1563.  
  1564.  
  1565. /****************************************************************************\
  1566. *
  1567. * Function:     BOOL MIDASsetStreamVolume(MIDASstreamHandle stream,
  1568. *                   unsigned volume)
  1569. *
  1570. * Description:  Changes the playback volume of a stream
  1571. *
  1572. * Input:        MIDASstreamHandle stream    Stream playing handle
  1573. *               unsigned volume         New volume
  1574. *
  1575. * Returns:      TRUE if succesful, FALSE if not
  1576. *
  1577. \****************************************************************************/
  1578.  
  1579. _FUNC(BOOL) MIDASsetStreamVolume(MIDASstreamHandle stream, unsigned volume)
  1580. {
  1581.     int         error;
  1582.  
  1583.     if ( (error = strSetStreamVolume((strStream*) stream, volume)) != OK )
  1584.     {
  1585.         lastError = error;
  1586.         return FALSE;
  1587.     }
  1588.  
  1589.     return TRUE;
  1590. }
  1591.  
  1592.  
  1593.  
  1594.  
  1595. /****************************************************************************\
  1596. *
  1597. * Function:     BOOL MIDASsetStreamPanning(MIDASstreamHandle stream,
  1598. *                   int panning)
  1599. *
  1600. * Description:  Changes the panning position of a stream
  1601. *
  1602. * Input:        MIDASstreamHandle stream    Stream playing handle
  1603. *               int panning             New panning position
  1604. *
  1605. * Returns:      TRUE if succesful, FALSE if not
  1606. *
  1607. \****************************************************************************/
  1608.  
  1609. _FUNC(BOOL) MIDASsetStreamPanning(MIDASstreamHandle stream, int panning)
  1610. {
  1611.     int         error;
  1612.  
  1613.     if ( (error = strSetStreamPanning((strStream*) stream, panning)) != OK )
  1614.     {
  1615.         lastError = error;
  1616.         return FALSE;
  1617.     }
  1618.  
  1619.     return TRUE;
  1620. }
  1621.  
  1622.  
  1623.  
  1624. #endif /* #ifdef SUPPORTSTREAMS */
  1625.  
  1626.  
  1627. #ifdef __WIN32__
  1628.  
  1629.  
  1630. int PASCAL WEP(short nParameter)
  1631. {
  1632.     /* The DLL is being unloaded by a process */
  1633.  
  1634.     /* Stop playing in a thread: */
  1635.     if ( MIDASthread )
  1636.     {
  1637.         MIDASstopBackgroundPlay();
  1638.     }
  1639.  
  1640.     /* Close MIDAS - this can safely be done many times: */
  1641.     MIDASclose();
  1642.  
  1643.     DLLinUse = 0;
  1644.  
  1645.     return 1;
  1646. }
  1647.  
  1648.  
  1649. /* The DLL main: */
  1650.  
  1651.  
  1652. int APIENTRY LibMain(HANDLE hdll, DWORD reason, LPVOID reserved)
  1653. {
  1654.     switch ( reason )
  1655.     {
  1656.         case DLL_PROCESS_ATTACH:
  1657.             /* The DLL is loaded by a process. Check that the DLL is not in
  1658.                use by some other process, and if not, mark that we are in use
  1659.                and set to default config: */
  1660.             if ( DLLinUse )
  1661.                 return 0;               /* Only one program can use MIDAS */
  1662.  
  1663.             DLLinUse = 1;
  1664.             MIDASstartup();
  1665.  
  1666.             break;
  1667.  
  1668.         case DLL_PROCESS_DETACH:
  1669.             /* The DLL is being unloaded by a process */
  1670.  
  1671.             /* Stop playing in a thread: */
  1672.             if ( MIDASthread )
  1673.             {
  1674.                 MIDASstopBackgroundPlay();
  1675.             }
  1676.  
  1677.             /* Close MIDAS - this can safely be done many times: */
  1678.             MIDASclose();
  1679.  
  1680.             DLLinUse = 0;
  1681.  
  1682.             break;
  1683.  
  1684.         /* We aren't interested in thread creation */
  1685.     }
  1686.  
  1687.     return 1;
  1688. }
  1689.  
  1690.  
  1691. #endif /* #ifdef __WIN32__ */
  1692.  
  1693.  
  1694. /*
  1695.  * $Log: midasdll.c,v $
  1696.  * Revision 1.6  1997/01/16 19:57:19  pekangas
  1697.  * Removed a couple of Visual C warnings
  1698.  *
  1699.  * Revision 1.5  1997/01/16 19:43:55  pekangas
  1700.  * Removed a warning
  1701.  *
  1702.  * Revision 1.4  1997/01/16 18:41:59  pekangas
  1703.  * Changed copyright messages to Housemarque
  1704.  *
  1705.  * Revision 1.3  1997/01/16 18:26:27  pekangas
  1706.  * Added numerous new functions
  1707.  *
  1708.  * Revision 1.2  1996/12/07 22:19:56  pekangas
  1709.  * No change
  1710.  *
  1711.  * Revision 1.1  1996/09/25 18:38:02  pekangas
  1712.  * Initial revision
  1713.  *
  1714. */